package com.zzyl.nursing.controller;

import com.zzyl.common.core.domain.R;
import com.zzyl.nursing.vo.TreeVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zzyl.common.annotation.Log;
import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.enums.BusinessType;
import com.zzyl.nursing.domain.Floor;
import com.zzyl.nursing.service.IFloorService;
import com.zzyl.common.utils.poi.ExcelUtil;
import com.zzyl.common.core.page.TableDataInfo;

/**
 * 楼层Controller
 *
 * @author brian
 * @date 2025-09-27
 */
@RestController
@RequestMapping("/elder/floor")
@Api(tags = "楼层相关接口")
public class FloorController extends BaseController {
    @Autowired
    private IFloorService floorService;

    /**
     * 查询楼层列表
     */
    @PreAuthorize("@ss.hasPermi('elder:floor:list')")
    @GetMapping("/list")
    @ApiOperation("查询楼层列表")
    public TableDataInfo<List<Floor>> list(@ApiParam(value = "楼层查询条件") Floor floor) {
        startPage();
        List<Floor> list = floorService.selectFloorList(floor);
        return getDataTable(list);
    }

    /**
     * 导出楼层列表
     */
    @PreAuthorize("@ss.hasPermi('elder:floor:export')")
    @Log(title = "楼层", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation("导出楼层列表")
    public void export(HttpServletResponse response, @ApiParam(value = "楼层查询条件") Floor floor) {
        List<Floor> list = floorService.selectFloorList(floor);
        ExcelUtil<Floor> util = new ExcelUtil<Floor>(Floor.class);
        util.exportExcel(response, list, "楼层数据");
    }

    /**
     * 获取楼层详细信息
     */
    @PreAuthorize("@ss.hasPermi('elder:floor:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation("获取楼层详细信息")
    public R<Floor> getInfo(@ApiParam(value = "楼层ID", required = true) @PathVariable("id") Long id) {
        return R.ok(floorService.selectFloorById(id));
    }

    /**
     * 新增楼层
     */
    @PreAuthorize("@ss.hasPermi('elder:floor:add')")
    @Log(title = "楼层", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增楼层")
    public AjaxResult add(@ApiParam(value = "楼层实体", required = true) @RequestBody Floor floor) {
        return toAjax(floorService.insertFloor(floor));
    }

    /**
     * 修改楼层
     */
    @PreAuthorize("@ss.hasPermi('elder:floor:edit')")
    @Log(title = "楼层", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改楼层")
    public AjaxResult edit(@ApiParam(value = "楼层实体", required = true) @RequestBody Floor floor) {
        return toAjax(floorService.updateFloor(floor));
    }

    /**
     * 删除楼层
     */
    @PreAuthorize("@ss.hasPermi('elder:floor:remove')")
    @Log(title = "楼层", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @ApiOperation("删除楼层")
    public AjaxResult remove(@ApiParam(value = "楼层ID数组", required = true) @PathVariable Long[] ids) {
        return toAjax(floorService.deleteFloorByIds(ids));
    }

    /**
     * 根据床位状态查询所有楼层数据
     * @param status
     * @return
     */
    @GetMapping("/getRoomAndBedByBedStatus/{status}")
    @ApiOperation("按照状态查询楼层房间床位-树形结构")
    public R<List<TreeVo>> getRoomAndBedByBedStatus(@ApiParam(value = "床位状态(未入住0, 已入住1)", required = true) @PathVariable("status") Integer status){
        List<TreeVo> list = floorService.getRoomAndBedByBedStatus(status);
        return R.ok(list);
    }
}
